package com.mm.dss.demo.adapter;


import android.content.Context;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.mm.dss.demo.R;
import java.io.File;
/**
 * Created by Lenovo on 2018/6/14.
 */

public class Myhttpadapter extends  RecyclerView.Adapter<Myhttpadapter.ViewHolder> implements View.OnClickListener{
    String[] strlist;
    Context context;
    private onRecyclerItemClickerListener mListener;
    public Myhttpadapter(String[] strlist, Context context){
        this.strlist=strlist;
        this.context=context;
    }
    /*      *//**
     * 增加点击监听
     */
      public void setItemListener(onRecyclerItemClickerListener mListener) {
          this.mListener = mListener;
      }
    @Override
    public Myhttpadapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.itme_recyimgview,null);
          Myhttpadapter.ViewHolder vh=new Myhttpadapter.ViewHolder(view);
          view.setOnClickListener(this);
        return vh;
    }


    @Override
    public void onBindViewHolder(Myhttpadapter.ViewHolder holder, final int position) {
        File file = new File(strlist[position]);
        Log.i("图片地址",file+"?"+ Environment.getExternalStorageDirectory()+"?"+strlist[position]);
        Glide.with(context).load(strlist[position]).into(holder.img);

        holder.itemView.setTag(position);

    }
    @Override
    public int getItemCount() {
        return strlist.length;
    }

    @Override
    public void onClick(View view) {
          if (mListener!=null){
              mListener.onItemClick(view, strlist, (int)view.getTag());
          }

    }

    public  class ViewHolder extends RecyclerView.ViewHolder{
        public ImageView img;
        public ViewHolder(View itemView) {
            super(itemView);
            img=(ImageView)itemView.findViewById(R.id.img);
        }
    }

    public  interface onRecyclerItemClickerListener {
        void onItemClick(View view, String[] strlist, int i);
    }
}